import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [

    {
      path: '/',
      name: 'Login',
      component: () => import('../views/LoginView.vue'),
    },
    {
      path: '/index',
      name: 'index',
      component: () => import('../views/Indexview.vue'),
      redirect: '/index/home', // 添加重定向
      children: [

        {
          path: 'home', // 改为相对路径
          name: 'home',
          component: () => import('../views/HomePageView.vue'),
        },
        {
          path: 'Pharmacy', // 改为相对路径
          name: 'Pharmacy',
          component: () => import('../views/ContentManagement/PharmacyView.vue'),
        },
        {
          path: 'CarouselChart', // 改为相对路径
          name: 'CarouselChart',
          component: () => import('../views/ContentManagement/CarouselChartView.vue'),
        },
        {
          path: 'HospitalDepartments', // 改为相对路径
          name: 'HospitalDepartments',
          component: () => import('../views/ContentManagement/HospitalDepartmentsView.vue'),
        },
        {
          path: 'Hospital', // 改为相对路径
          name: 'Hospital',
          component: () => import('../views/ContentManagement/HospitalView.vue'),
        },
        {
          path: 'Question', // 改为相对路径
          name: 'Question',
          component: () => import('../views/ContentManagement/QuestionView.vue'),
        },
        {
          path: 'PopularScienceDisease', // 改为相对路径
          name: 'PopularScienceDisease',
          component: () => import('../views/ContentManagement/PopularScienceDiseaseView.vue'),
        },

      ]
    },
    // 添加重定向规则
    {
      path: '/home',
      redirect: '/index/home'
    },
    {
      path: '/Pharmacy',
      redirect: '/index/Pharmacy'
    },
    {
      path: '/CarouselChart',
      redirect: '/index/CarouselChart'
    },
    {
      path: '/HospitalDepartments',
      redirect: '/index/HospitalDepartments'
    },
    {
      path: '/Hospital',
      redirect: '/index/Hospital'
    },
    {
      path: '/Question',
      redirect: '/index/Question'
    },
    {
      path: '/PopularScienceDisease',
      redirect: '/index/PopularScienceDisease'
    },
  ],
})

export default router
